<?php
namespace Admin\Controller;
class TjController extends AdminController {
	public function _initialize(){
		parent::_initialize();
	}
	/**
	 * 统计全站信息
	 */
	public function index(){
		//今日注册量
		$user_num=M('Member')->count();
		$data['user_num']=$user_num;
		//今日平均成交价格
		$wheretrade['add_time']=array('between',[strtotime(date("Y-m-d"),time()),time()]);
		$wheretrade['money_type']=1;
		$all_money=M('trade_log')->where($wheretrade)->sum('money');
		$data['all_money']=$all_money;
		//会员可用GHC总和
		 $ghc_sum=M('Member_money')->sum('money2');
		$data['ghc_num']=$ghc_sum; 
		//会员可用CNT总和
		 $cnt_num=M('Member_money')->sum('money1');
		$data['cnt_num']=$cnt_num; 
		$data['admin']=$this->user;
		$last_log=M('Admin_log')->where(["username"=>$this->user['username']])->order('add_time desc')->limit(1)->select();
		$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$last_log[0]['ip'];
		$result=$this->curl_get($url);
		$data['ipinfo']=$result['data'];
		$data['admin_log']=$last_log;
		$data['status']=1;
		$this->ajaxReturn($data);
	}
	public function getKline(){
		header('Content-Type: text/javascript; charset=utf-8');
		$filename = __APP__."KlineData/KLineData_kline_2_.js";
		$file = file_get_contents($filename);
		$file_ex   = file_exists($filename);
		if($file_ex == false || $file == ''){
			echo false;
		}else{
			$data['list']=stripslashes($file);
			$data['status']=1;
			$this->ajaxReturn($data);
		}
	}
	public function getBing(){
		$arr=array();
		$level1=M('Member')->where('level = 1')->count();
		array_push($arr, $level1);
		$level2=M('Member')->where('level = 2')->count();
		array_push($arr, $level2);
		$level3=M('Member')->where('level = 3')->count();
		array_push($arr, $level3);
		$level4=M('Member')->where('level = 4')->count();
		array_push($arr, $level4);
		$data['list']=$arr;
		$data['status']=1;
		$this->ajaxReturn($data);
	}
	public function getTradeRecord(){
	    $list = M('Project_log pl')
	    ->field('pl.*,u.member_id,u.username,c.currency_id,c.currency_mark')
	    ->join("JOIN yang_member AS u ON u.member_id = pl.uid")
	    ->join('__CURRENCY1__ as c on c.currency_id = pl.type')
	    ->limit(20)->select();
	    foreach ($list as $k=>$v){
	        $list[$k]['type_name'] = M('Currency1')->where(['currency_id'=>$v['type']])->find()['currency_mark'];
	    }
	    $return['data'] = $list;
	    $return['status'] = 1;
	    $this->ajaxReturn($return);
	}
	public function getTradeNum(){
		$arr=array();
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time()),time()));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time()),$num/2);
		array_push($arr, $newarr);
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time())-3600*24,strtotime(date("Y-m-d"),time())));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time())-3600*24,$num/2);
		array_push($arr, $newarr);
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time())-3600*24*2,strtotime(date("Y-m-d"),time())-3600*24));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time())-3600*24*2,$num/2);
		array_push($arr, $newarr);
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time())-3600*24*3,strtotime(date("Y-m-d"),time())-3600*24*2));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time())-3600*24*3,$num/2);
		array_push($arr, $newarr);
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time())-3600*24*4,strtotime(date("Y-m-d"),time())-3600*24*3));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time())-3600*24*4,$num/2);
		array_push($arr, $newarr);
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time())-3600*24*5,strtotime(date("Y-m-d"),time())-3600*24*4));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time())-3600*24*5,$num/2);
		array_push($arr, $newarr);
		$where['add_time']=array('between',array(strtotime(date("Y-m-d"),time())-3600*24*6,strtotime(date("Y-m-d"),time())-3600*24*5));
		$num=M('trade')->where($where)->sum('money');
		$newarr=array(strtotime(date("Y-m-d"),time())-3600*24*6,$num/2);
		array_push($arr, $newarr);
		$data['list']=array_reverse($arr);
		$data['status']=1;
		$this->ajaxReturn($data);
	}
}